﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Navigation;
using Microsoft.Phone.Controls;
using Microsoft.Phone.Shell;
using ODS.Model;
using ODS.Config;
using ODS.WebService.DeviceMonitor;
using ODS.Utils;
using System.Threading.Tasks;

namespace ODS.UserControls
{
    public partial class SettingAlertPage : UserControl
    {
        public SettingPage parrentPage;

        List<DeviceMonitorModel> listDeviceMonitorModel;
        public List<DeviceMonitorModel> DeviceMonitorModelList
        {
            get { return listDeviceMonitorModel; }
            set { listDeviceMonitorModel = value; }
        }

        Place location1 = new Place();
        Place location2 = new Place();
        Place location3 = new Place();

        int  rowLocationShowChooseLocationView;

        public SettingAlertPage()
        {
            InitializeComponent();
        }

        public void loadDataForView()
        {
            if (listDeviceMonitorModel.Count > 0)
            {
                foreach (DeviceMonitorModel deviceMonitorModel in listDeviceMonitorModel)
                {
                    switch(int.Parse(deviceMonitorModel.MonitorType))
                    {
                        case Constants.MONITOR_TYPE_HARSH_CORNERING:
                            if (deviceMonitorModel.Processing)
                            {
                                //determine state
                                togglebtn_harshBraking.IsThreeState = true;
                                togglebtn_harshBraking.IsEnabled = false;
                                togglebtn_harshBraking.IsChecked = null;
                            }
                            else
                            {
                                togglebtn_harshBraking.IsEnabled = true;
                                togglebtn_harshBraking.IsThreeState = false;
                                togglebtn_harshBraking.IsChecked = true;
                            }
                            break;
                        case Constants.MONITOR_TYPE_IMPACT:
                            if (deviceMonitorModel.Processing)
                            {
                                //determine state
                                togglebtn_impact.IsThreeState = true;
                                togglebtn_impact.IsEnabled = false;
                                togglebtn_impact.IsChecked = null;
                            }
                            else
                            {
                                togglebtn_impact.IsEnabled = true;
                                togglebtn_impact.IsThreeState = false;
                                togglebtn_impact.IsChecked = true;
                            }
                            break;
                        case Constants.MONITOR_TYPE_GEOFENCE:
                            setDataForMONITOR_TYPE_GEOFENCE(deviceMonitorModel);
                            break;
                        case Constants.MONITOR_TYPE_SPEED:
                            #region hande MONITOR_TYPE_SPEED
                            if (deviceMonitorModel.Processing)
                            {
                                //determine state
                                togglebtn_speed.IsThreeState = true;
                                togglebtn_speed.IsEnabled = false;
                                togglebtn_speed.IsChecked = null;
                            }
                            else
                            {
                                togglebtn_speed.IsEnabled = true;
                                togglebtn_speed.IsThreeState = false;
                                togglebtn_speed.IsChecked = true;
                            }

                            int count = deviceMonitorModel.ArrayParameter.Count;
                            for (int i = count - 1; i >= 0; i-- )
                            {
                                MonitorParameterModel monitorParaModel = deviceMonitorModel.ArrayParameter.ElementAt(i);
                                if (monitorParaModel.NameParameter.ToLower().Equals("threshold"))
                                {
                                    tb_speed.MyText = monitorParaModel.Value;
                                    //break;
                                }
                                else
                                {
                                    deviceMonitorModel.ArrayParameter.Remove(monitorParaModel);
                                }
                            }
                           
                            #endregion
                            break;
                        case Constants.MONITOR_TYPE_IDLE:
                            #region handle MONITOR_TYPE_IDLE
                            if (deviceMonitorModel.Processing)
                            {
                                //determine state
                                togglebtn_idle.IsThreeState = true;
                                togglebtn_idle.IsEnabled = false;
                                togglebtn_idle.IsChecked = null;
                            }
                            else
                            {
                                togglebtn_idle.IsEnabled = true;
                                togglebtn_idle.IsThreeState = false;
                                togglebtn_idle.IsChecked = true;
                            }

                            count = deviceMonitorModel.ArrayParameter.Count;
                            for (int i = count - 1; i >= 0; i-- )
                            {
                                MonitorParameterModel monitorParaModel = deviceMonitorModel.ArrayParameter.ElementAt(i);
                                if (monitorParaModel.NameParameter.ToLower().Equals("period"))
                                {
                                    tb_idle.MyText = monitorParaModel.Value;
                                    //break;
                                }
                                else
                                {
                                    deviceMonitorModel.ArrayParameter.Remove(monitorParaModel);
                                }
                            }
                            #endregion
                            break;
                        case Constants.MONITOR_TYPE_TOWING:
                            break;
                        case Constants.MONITOR_TYPE_HARSH_BRAKING:
                            if (deviceMonitorModel.Processing)
                            {
                                //determine state
                                togglebtn_harshBraking.IsThreeState = true;
                                togglebtn_harshBraking.IsEnabled = false;
                                togglebtn_harshBraking.IsChecked = null;
                            }
                            else
                            {
                                togglebtn_harshBraking.IsEnabled = true;
                                togglebtn_harshBraking.IsThreeState = false;
                                togglebtn_harshBraking.IsChecked = true;
                            }
                            break;
                    }
                }
            }
        }

        void setDataForMONITOR_TYPE_GEOFENCE(DeviceMonitorModel deviceMonitorModel)
        {
            MonitorParameterModel parameterIndex = null;
            MonitorParameterModel parameterLatitude = null;
            MonitorParameterModel parameterLongitude = null;
            MonitorParameterModel parameterRadius = null;
            foreach (MonitorParameterModel monitorParaModel in deviceMonitorModel.ArrayParameter)
            {
                if (monitorParaModel.NameParameter.Equals("index"))
                {
                    parameterIndex = monitorParaModel;
                }
                else if (monitorParaModel.NameParameter.Equals("latitude"))
                {
                    parameterLatitude = monitorParaModel;
                }
                else if (monitorParaModel.NameParameter.Equals("longitude"))
                {
                    parameterLongitude = monitorParaModel;
                }
                else if (monitorParaModel.NameParameter.Equals("radius"))
                {
                    parameterRadius = monitorParaModel;
                }
            }

            GoogleServiceHandler googleService = new GoogleServiceHandler();
            switch (int.Parse(parameterIndex.Value))
            {
                case 1:
                    if (deviceMonitorModel.Processing)
                    {
                        //determine state
                        togglebtn_pointLocation1.IsThreeState = true;
                        togglebtn_pointLocation1.IsEnabled = false;
                        togglebtn_pointLocation1.IsChecked = null;
                    }
                    else
                    {
                        togglebtn_pointLocation1.IsEnabled = true;
                        togglebtn_pointLocation1.IsThreeState = false;
                        togglebtn_pointLocation1.IsChecked = true;
                    }
                    tb_radius1.MyText = parameterRadius.Value;

                    location1.Lattitude = double.Parse(parameterLatitude.Value);
                    location1.Longitude = double.Parse(parameterLongitude.Value);
  
                    googleService.GetPlaceByLatLng(location1.Lattitude, location1.Longitude);
                    googleService.OnGetGeocodingLocation += googleService_OnGetGeocodingLocation1;
                    break;
                case 2:
                    if (deviceMonitorModel.Processing)
                    {
                        //determine state
                        togglebtn_pointLocation2.IsThreeState = true;
                        togglebtn_pointLocation2.IsEnabled = false;
                        togglebtn_pointLocation2.IsChecked = null;
                    }
                    else
                    {
                        togglebtn_pointLocation2.IsEnabled = true;
                        togglebtn_pointLocation2.IsThreeState = false;
                        togglebtn_pointLocation2.IsChecked = true;
                    }
                    tb_radius2.MyText = parameterRadius.Value;

                    location2.Lattitude = double.Parse(parameterLatitude.Value);
                    location2.Longitude = double.Parse(parameterLongitude.Value);
      
                    googleService.GetPlaceByLatLng(location2.Lattitude, location2.Longitude);
                    googleService.OnGetGeocodingLocation += googleService_OnGetGeocodingLocation2;
                    
                    break;
                case 3:
                    if (deviceMonitorModel.Processing)
                    {
                        //determine state
                        togglebtn_pointLocation3.IsThreeState = true;
                        togglebtn_pointLocation3.IsEnabled = false;
                        togglebtn_pointLocation3.IsChecked = null;
                    }
                    else
                    {
                        togglebtn_pointLocation3.IsEnabled = true;
                        togglebtn_pointLocation3.IsThreeState = false;
                        togglebtn_pointLocation3.IsChecked = true;
                    }

                    tb_radius3.MyText = parameterRadius.Value;

                    location3.Lattitude = double.Parse(parameterLatitude.Value);
                    location3.Longitude = double.Parse(parameterLongitude.Value);
      
                    googleService.GetPlaceByLatLng(location3.Lattitude, location3.Longitude);
                    googleService.OnGetGeocodingLocation += googleService_OnGetGeocodingLocation3;
                    break;
            }
        }

        public async Task Apply()
        {
            if (ValidateInput())
            {
                //this.listDeviceMonitorModel.Clear();

                List<DeviceMonitorModel> newDeviceMonitorModelList = new List<DeviceMonitorModel>();

                DeviceMonitorModel deviceMonitorModel = null;
                MonitorParameterModel parameterModel = null;
                if (togglebtn_harshBraking.IsChecked == true)
                {
                    deviceMonitorModel = new DeviceMonitorModel();
                    deviceMonitorModel.MonitorType = Constants.MONITOR_TYPE_HARSH_BRAKING.ToString();
                    newDeviceMonitorModelList.Add(deviceMonitorModel);

                    deviceMonitorModel = new DeviceMonitorModel();
                    deviceMonitorModel.MonitorType = Constants.MONITOR_TYPE_HARSH_CORNERING.ToString();
                    newDeviceMonitorModelList.Add(deviceMonitorModel);
                }

                if (togglebtn_impact.IsChecked == true)
                {
                    deviceMonitorModel = new DeviceMonitorModel();
                    deviceMonitorModel.MonitorType = Constants.MONITOR_TYPE_IMPACT.ToString();
                    newDeviceMonitorModelList.Add(deviceMonitorModel);
                }

                if (togglebtn_idle.IsChecked == true)
                {
                    deviceMonitorModel = new DeviceMonitorModel();
                    deviceMonitorModel.ArrayParameter = new List<MonitorParameterModel>();
                    deviceMonitorModel.MonitorType = Constants.MONITOR_TYPE_IDLE.ToString();

                    parameterModel = new MonitorParameterModel();
                    parameterModel.NameParameter = "period";
                    parameterModel.Value = tb_idle.MyText;                    
                    deviceMonitorModel.ArrayParameter.Add(parameterModel);

                    //parameterModel = new MonitorParameterModel();
                    //parameterModel.NameParameter = "threshold";
                    //parameterModel.Value = tb_idle.MyText;
                    //deviceMonitorModel.ArrayParameter.Add(parameterModel);

                    newDeviceMonitorModelList.Add(deviceMonitorModel);
                }

                if (togglebtn_speed.IsChecked == true)
                {
                    deviceMonitorModel = new DeviceMonitorModel();
                    deviceMonitorModel.ArrayParameter = new List<MonitorParameterModel>();
                    deviceMonitorModel.MonitorType = Constants.MONITOR_TYPE_SPEED.ToString();

                    //parameterModel = new MonitorParameterModel();
                    //parameterModel.NameParameter = "period";
                    //parameterModel.Value = tb_speed.MyText;
                    //deviceMonitorModel.ArrayParameter.Add(parameterModel);

                    parameterModel = new MonitorParameterModel();
                    parameterModel.NameParameter = "threshold";
                    parameterModel.Value = tb_speed.MyText;
                    deviceMonitorModel.ArrayParameter.Add(parameterModel);

                    newDeviceMonitorModelList.Add(deviceMonitorModel);
                }

                if (togglebtn_pointLocation1.IsChecked == true)
                {
                    deviceMonitorModel = new DeviceMonitorModel();
                    deviceMonitorModel.ArrayParameter = new List<MonitorParameterModel>();
                    deviceMonitorModel.MonitorType = Constants.MONITOR_TYPE_GEOFENCE.ToString();

                    parameterModel = new MonitorParameterModel();
                    parameterModel.NameParameter = "index";
                    parameterModel.Value = "1";
                    deviceMonitorModel.ArrayParameter.Add(parameterModel);

                    parameterModel = new MonitorParameterModel();
                    parameterModel.NameParameter = "latitude";
                    parameterModel.Value = location1.Lattitude.ToString();
                    deviceMonitorModel.ArrayParameter.Add(parameterModel);

                    parameterModel = new MonitorParameterModel();
                    parameterModel.NameParameter = "longitude";
                    parameterModel.Value = location1.Longitude.ToString();
                    deviceMonitorModel.ArrayParameter.Add(parameterModel);

                    parameterModel = new MonitorParameterModel();
                    parameterModel.NameParameter = "radius";
                    parameterModel.Value = tb_radius1.MyText;
                    deviceMonitorModel.ArrayParameter.Add(parameterModel);

                    newDeviceMonitorModelList.Add(deviceMonitorModel);
                }

                if (togglebtn_pointLocation2.IsChecked == true)
                {
                    deviceMonitorModel = new DeviceMonitorModel();
                    deviceMonitorModel.ArrayParameter = new List<MonitorParameterModel>();
                    deviceMonitorModel.MonitorType = Constants.MONITOR_TYPE_GEOFENCE.ToString();

                    parameterModel = new MonitorParameterModel();
                    parameterModel.NameParameter = "index";
                    parameterModel.Value = "2";
                    deviceMonitorModel.ArrayParameter.Add(parameterModel);

                    parameterModel = new MonitorParameterModel();
                    parameterModel.NameParameter = "latitude";
                    parameterModel.Value = location2.Lattitude.ToString();
                    deviceMonitorModel.ArrayParameter.Add(parameterModel);

                    parameterModel = new MonitorParameterModel();
                    parameterModel.NameParameter = "longitude";
                    parameterModel.Value = location2.Longitude.ToString();
                    deviceMonitorModel.ArrayParameter.Add(parameterModel);

                    parameterModel = new MonitorParameterModel();
                    parameterModel.NameParameter = "radius";
                    parameterModel.Value = tb_radius2.MyText;
                    deviceMonitorModel.ArrayParameter.Add(parameterModel);

                    newDeviceMonitorModelList.Add(deviceMonitorModel);
                }

                if (togglebtn_pointLocation3.IsChecked == true)
                {
                    deviceMonitorModel = new DeviceMonitorModel();
                    deviceMonitorModel.ArrayParameter = new List<MonitorParameterModel>();
                    deviceMonitorModel.MonitorType = Constants.MONITOR_TYPE_GEOFENCE.ToString();

                    parameterModel = new MonitorParameterModel();
                    parameterModel.NameParameter = "index";
                    parameterModel.Value = "3";
                    deviceMonitorModel.ArrayParameter.Add(parameterModel);

                    parameterModel = new MonitorParameterModel();
                    parameterModel.NameParameter = "latitude";
                    parameterModel.Value = location3.Lattitude.ToString();
                    deviceMonitorModel.ArrayParameter.Add(parameterModel);

                    parameterModel = new MonitorParameterModel();
                    parameterModel.NameParameter = "longitude";
                    parameterModel.Value = location3.Longitude.ToString();
                    deviceMonitorModel.ArrayParameter.Add(parameterModel);

                    parameterModel = new MonitorParameterModel();
                    parameterModel.NameParameter = "radius";
                    parameterModel.Value = tb_radius3.MyText;
                    deviceMonitorModel.ArrayParameter.Add(parameterModel);

                    newDeviceMonitorModelList.Add(deviceMonitorModel);
                }

                bool isSuccess = await updateDeviceMonitor(newDeviceMonitorModelList);
                if (isSuccess)
                {
                    MessageBox.Show("Update device is successfully");

                    App.BackToMainPage(parrentPage);
                }
            }
        }

        async Task<bool> updateDeviceMonitor(List<DeviceMonitorModel> updateDeviceMonitorModelList)
        {
            for (int i = 1; i <= 7; i++)
            {
                DeviceMonitorModel oldDeviceMonitor = GetDeviceMonitorModel(listDeviceMonitorModel, i);
                DeviceMonitorModel newDeviceMonitor = GetDeviceMonitorModel(updateDeviceMonitorModelList, i);
                InfoResult result = null;
                if ((oldDeviceMonitor == null && newDeviceMonitor == null) )
                {
                    //do nothing
                }
                else if (oldDeviceMonitor == null && newDeviceMonitor != null)
                {
                    result = await AddDeviceMonitorService.AddDeviceMonitor(newDeviceMonitor, App.currentDeviceModel.DeviceIMEI, i.ToString());
                    
                }
                else if ( oldDeviceMonitor.Processing == false && oldDeviceMonitor != null && newDeviceMonitor == null)
                {
                    result = await RemoveDeviceMonitorSevice.RemoveDeviceMonitor(App.currentDeviceModel.DeviceIMEI, i.ToString());
                }
                else if (oldDeviceMonitor.Processing == false )
                {
                    bool isSame = false;
                    if (oldDeviceMonitor.ArrayParameter != null)
                    {
                        int count = oldDeviceMonitor.ArrayParameter.Count;
                        for (int j = 0; j < count; j++ )
                        {
                            MonitorParameterModel oldMonitorParaModel = oldDeviceMonitor.ArrayParameter.ElementAt(j);
                            MonitorParameterModel newMonitorParaModel = GetMonitorParameterModel(newDeviceMonitor, oldMonitorParaModel.NameParameter);
                            if (newMonitorParaModel != null)
                            {
                                if (oldMonitorParaModel.Value != newMonitorParaModel.Value)
                                {
                                    isSame = false;
                                    break;
                                }
                            }
                            else
                            {
                                isSame = false;
                                break;
                            }
                        }
                    }else{
                        isSame = true;
                    }

                    if (!isSame)
                    {
                        if (int.Parse(newDeviceMonitor.MonitorType) == Constants.MONITOR_TYPE_SPEED || int.Parse(newDeviceMonitor.MonitorType) == Constants.MONITOR_TYPE_IDLE)
                            result = await UpdateDeviceMonitorService.UpdateDeviceMonitor(newDeviceMonitor, App.currentDeviceModel.DeviceIMEI, newDeviceMonitor.MonitorType);
                        else if (int.Parse(newDeviceMonitor.MonitorType) == Constants.MONITOR_TYPE_GEOFENCE)
                        {
                            int indexParameter  = 0;
                            foreach (MonitorParameterModel paraMeter in newDeviceMonitor.ArrayParameter)
                            {
                                if (paraMeter.NameParameter.Equals("index"))
                                {
                                    indexParameter = int.Parse(paraMeter.Value);
                                    break;
                                }

                            }
                            result = await UpdateDeviceIndexedMonitorService.UpdateDeviceIndexedMonitor(newDeviceMonitor, App.currentDeviceModel.DeviceIMEI, indexParameter);
                        }
                    }
                    
                }

                if (result != null)
                {
                    if (result.IsSuccess)
                    {
                        if ((String)result.ReturnedObject != Constants.SUCCESS)
                        {
                            MessageBox.Show((String)result.ReturnedObject);
                            return false;
                        }
                        
                    }
                    else
                    {
                        MessageBox.Show(result.Error);
                        return false;
                    }
                }

            }

            return true;
        }

        DeviceMonitorModel GetDeviceMonitorModel(List<DeviceMonitorModel> listDeviceMonitorModel, int commandType)
        {
            foreach (DeviceMonitorModel deviceMonitor in listDeviceMonitorModel)
            {
                if (int.Parse(deviceMonitor.MonitorType) == commandType)
                {
                    return deviceMonitor;
                }
            }

            return null;

        }

        MonitorParameterModel GetMonitorParameterModel(DeviceMonitorModel deviceMonitorModel, String name)
        {
            foreach (MonitorParameterModel para in deviceMonitorModel.ArrayParameter)
            {
                if (para.NameParameter == name)
                {
                    return para;
                }
            }
            return null;
        }

        bool ValidateInput()
        {
            if (togglebtn_idle.IsChecked == true)
            {
                if (tb_idle.MyText == "")
                {
                    MessageBox.Show("Idling is empty. Please try again");
                    return false;

                }

                if (int.Parse(tb_idle.MyText) < 5 || int.Parse(tb_idle.MyText) > 240)
                {
                    MessageBox.Show("Idle value is no less than 5 mins and large than 240 mins . Please try again.");
                    return false;
                }
            }

            if (togglebtn_speed.IsChecked == true)
            {
                if (tb_speed.MyText == "")
                {
                    MessageBox.Show("Speeding is empty. Please try again");
                    return false;

                }

                if (int.Parse(tb_speed.MyText) < 50 || int.Parse(tb_speed.MyText) > 500)
                {
                    MessageBox.Show("Speeding value is no less than 50 km and large than 500 km. Please try again!");
                    return false;
                }
            }

            if (togglebtn_pointLocation1.IsChecked == true)
            {
                if (tb_pointLocation1.MyText == "")
                {
                    MessageBox.Show("Point location is empty. Please try again!");
                    return false;
                }

                if (tb_radius1.MyText == "" || int.Parse(tb_radius1.MyText) < 50)
                {
                    MessageBox.Show("Radius value is no less than 50m. Please try again!");
                    return false;
                }
            }

            if (togglebtn_pointLocation2.IsChecked == true)
            {
                if (tb_pointLocation2.MyText == "")
                {
                    MessageBox.Show("Point location is empty. Please try again!");
                    return false;
                }

                if (tb_radius2.MyText == "" || int.Parse(tb_radius2.MyText) < 50)
                {
                    MessageBox.Show("Radius value is no less than 50m. Please try again!");
                    return false;
                }
            }

            if (togglebtn_pointLocation3.IsChecked == true)
            {
                if (tb_pointLocation3.MyText == "")
                {
                    MessageBox.Show("Point location is empty. Please try again!");
                    return false;
                }

                if (tb_radius3.MyText == "" || int.Parse(tb_radius3.MyText) < 50)
                {
                    MessageBox.Show("Radius value is no less than 50m. Please try again!");
                    return false;
                }
            }

            return true;
        }

        #region delegate google service
        void googleService_OnGetGeocodingLocation1(string address, double lat, double lng)
        {
            tb_pointLocation1.MyText = address;
        }

        void googleService_OnGetGeocodingLocation2(string address, double lat, double lng)
        {
            tb_pointLocation2.MyText = address;
        }

        void googleService_OnGetGeocodingLocation3(string address, double lat, double lng)
        {
            tb_pointLocation3.MyText = address;
        }
        #endregion

        public void setLocation(Place place)
        {
            switch (rowLocationShowChooseLocationView)
            {
                case 1:
                    location1.Address = place.Address;
                    location1.Lattitude = place.Lattitude;
                    location1.Longitude = place.Longitude;

                    tb_pointLocation1.MyText = place.Address;
                    break;
                case 2:
                    location2.Address = place.Address;
                    location2.Lattitude = place.Lattitude;
                    location2.Longitude = place.Longitude;

                    tb_pointLocation2.MyText = place.Address;
                    break;
                case 3:
                    location3.Address = place.Address;
                    location3.Lattitude = place.Lattitude;
                    location3.Longitude = place.Longitude;

                    tb_pointLocation3.MyText = place.Address;
                    break;
            }
        }

        #region event
        private void togglebtn_pointLocation1_Checked(object sender, System.Windows.RoutedEventArgs e)
        {
            if (togglebtn_pointLocation2.IsChecked != null)
                togglebtn_pointLocation2.IsChecked = false;
            if (togglebtn_pointLocation3.IsChecked != null)
                togglebtn_pointLocation3.IsChecked = false;
        }

        private void togglebtn_pointLocation1_Unchecked(object sender, System.Windows.RoutedEventArgs e)
        {
        	// do nothing
        }

        private void togglebtn_pointLocation2_Checked(object sender, System.Windows.RoutedEventArgs e)
        {
            if (togglebtn_pointLocation1.IsChecked != null)
                togglebtn_pointLocation1.IsChecked = false;
            if (togglebtn_pointLocation3.IsChecked != null)
                togglebtn_pointLocation3.IsChecked = false;
        }

        private void togglebtn_pointLocation2_Unchecked(object sender, System.Windows.RoutedEventArgs e)
        {
        	// do nothing
        }

        private void togglebtn_pointLocation3_Checked(object sender, System.Windows.RoutedEventArgs e)
        {
            if (togglebtn_pointLocation2.IsChecked != null)
                togglebtn_pointLocation2.IsChecked = false;
            if (togglebtn_pointLocation2.IsChecked != null)
                togglebtn_pointLocation1.IsChecked = false;
        }

        private void togglebtn_pointLocation3_Unchecked(object sender, System.Windows.RoutedEventArgs e)
        {
        	// do nothing
        }

        private void btn_getLocation1_Click(object sender, System.Windows.RoutedEventArgs e)
        {
            parrentPage.showChooseLocationViewWithAnimation();
            rowLocationShowChooseLocationView = 1;
        }

        private void btn_getLocation2_Click(object sender, System.Windows.RoutedEventArgs e)
        {
            parrentPage.showChooseLocationViewWithAnimation();
            rowLocationShowChooseLocationView = 2;
        }

        private void btn_getLocation3_Click(object sender, System.Windows.RoutedEventArgs e)
        {
            parrentPage.showChooseLocationViewWithAnimation();
            rowLocationShowChooseLocationView = 3;
        }


        private void btn_showLocation1_Click(object sender, System.Windows.RoutedEventArgs e)
        {
            if (tb_pointLocation1.MyText.Length > 0)
            {
                MessageBox.Show(tb_pointLocation1.MyText);
            }
        }

        private void btn_showLocation2_Click(object sender, System.Windows.RoutedEventArgs e)
        {
            if (tb_pointLocation2.MyText.Length > 0)
            {
                MessageBox.Show(tb_pointLocation2.MyText);
            }
        }

        private void btn_showLocation3_Click(object sender, System.Windows.RoutedEventArgs e)
        {
            if (tb_pointLocation3.MyText.Length > 0)
            {
                MessageBox.Show(tb_pointLocation3.MyText);
            }
        }

        #endregion
    }
}
